﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Roslyn.Compilers;
using Roslyn.Compilers.CSharp;
namespace SymbolicComputation.AI
{
    public class Assessers
    {
        public static Int32 VariablesOnRight(String inEquation, String variableBeingSolvedFor)
        {
            //count number of variables on right that are being solved for and decrement for each one
            List<String> strs = Miscellaneous.Split(inEquation.ToString(), "==", true);
            string rhs = strs[strs.Count - 1];
            SyntaxNode rhsTree = Miscellaneous.EquationToSyntaxNode(rhs);
            SyntaxNode[] rhsDescendants = rhsTree.DescendentNodesAndSelf().ToArray();
            SyntaxNode[] rhsMatches = rhsDescendants.Where(x => x.ToString() == variableBeingSolvedFor).ToArray();
            return rhsMatches.Length;
        }

        public static Int32 RepeatedVariables(SyntaxNode inEquation, String variableNotToRepeat)
        {
            SyntaxNode[] descendants = inEquation.DescendentNodesAndSelf().ToArray();
            SyntaxNode[] matches = descendants.Where(x => x.ToString() == variableNotToRepeat).ToArray();
            return matches.Length;
        }

    }
}
